package com.cll.learn.monitor.task;

import com.cll.learn.monitor.bean.MethodInvokeInfo;
import com.cll.learn.monitor.util.TopPercentileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/10/10 13:39
 */
public class ConsoleTopPercentileTask implements Runnable {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleTopPercentileTask.class);

    @Override
    public void run() {
        LOGGER.info("===>>> 开始统计TopPercentile数据");
        final Map<String, List<MethodInvokeInfo>> currentList = TopPercentileUtil.METHOD_INVOKE_INFO_MAP;
        currentList.forEach((String methodName, List<MethodInvokeInfo> list) -> {
            LOGGER.info(methodName + "tp90 : " + TopPercentileUtil.getTopPercentile(list, 0.9) + "毫秒");
            LOGGER.info(methodName + "tp99 : " + TopPercentileUtil.getTopPercentile(list, 0.99) + "毫秒");
        });
        LOGGER.info("===>>> 统计TopPercentile数据完成");
    }
}
